load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "types",
    srcs = [
        "alias.go",
        "oid.go",
        "testutils.go",
        "types.go",
        "types_jsonpb.go",
    ],
    embed = [":types_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/types",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/geo/geopb",
        "//pkg/sql/lex",
        "//pkg/sql/oidext",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/sem/catid",
        "//pkg/util/errorutil/unimplemented",
        "//pkg/util/protoutil",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//jsonpb",
        "@com_github_gogo_protobuf//proto",
        "@com_github_lib_pq//oid",
    ],
)

go_test(
    name = "types_test",
    size = "small",
    srcs = [
        "types_test.go",
        "types_text_marshal_test.go",
    ],
    embed = [":types"],
    deps = [
        "//pkg/geo/geopb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/oidext",
        "//pkg/sql/sem/catid",
        "//pkg/util/protoutil",
        "@com_github_lib_pq//oid",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
    ],
)

proto_library(
    name = "types_proto",
    srcs = ["types.proto"],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/geo/geopb:geopb_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
    ],
)

go_proto_library(
    name = "types_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/types",
    proto = ":types_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/geo/geopb",
        "@com_github_gogo_protobuf//gogoproto",
    ],
)

disallowed_imports_test(
    "types",
    [
        "//pkg/clusterversion",
        "//pkg/roachpb",
    ],
)
